package br.com.toscano.gobra.domain;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity 
@Table(name="USUARIO")
public class Usuario extends ObjetoAbstrato {

	private static final long serialVersionUID = 13454534543354517L;

	public Object getValorDescricao() {
		return this.login;
	}

	public String getLabelAtributoDescricao() {return "Login";}
	public String getAtributoDescricao() {
		return "login";
	}

	public Object getKey() {
		return this.getId();
	}

	public Usuario(){
		
	}

	public Usuario(String nome, String login, String senha, String email,
			List<Perfil> listaPerfil) {
		super();
		this.nome = nome;
		this.login = login;
		this.senha = senha;
		this.email = email;
		this.listaPerfil = listaPerfil;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name="PERF_ID")
	private Long id;
	
	@Column(name="PERF_NOME", nullable=false, length=255)
	private String nome;

	@Column(name="PERF_LOGIN", nullable=false, length=255)
	private String login;

	@Column(name="PERF_SENHA", nullable=false, length=255)
	private String senha;

	@Column(name="PERF_EMAIL", nullable=false, length=255)
	private String email;

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name="PERFIL_USUARIO",
            joinColumns = @JoinColumn( name="USUA_ID"),
            inverseJoinColumns = @JoinColumn( name="PERF_ID")
	)
	private List<Perfil> listaPerfil;

	public Long getId() {
		return id;
	}
	
	public void setId(Long id) {
		this.id = id;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public List<Perfil> getListaPerfil() {
		return listaPerfil;
	}

	public void setListaPerfil(List<Perfil> listaPerfil) {
		this.listaPerfil = listaPerfil;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}
	
	



	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if(!this.getClass().equals(obj.getClass()))
			return false;
		if (getClass() != obj.getClass())
			return false;
		Usuario other = (Usuario) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}

	
}